package com.study.sbsummary.controller;

import com.study.sbsummary.model.Doc;
import com.study.sbsummary.model.DocRequestDTO;
import com.study.sbsummary.model.Response;
import com.study.sbsummary.model.dto.DocContentVO;
import com.study.sbsummary.utils.AppVersionUtil;
import com.study.sbsummary.utils.ThreadLocalContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.util.List;

/**
 * @author: biturd
 * @date: 2022/3/25 14:28
 * @description:
 */
@Slf4j
@RestController
public class DocController {
    /**
     * @about 单图内容详情页
     * @from http://ydwiki.yidian-inc.com/pages/viewpage.action?pageId=77568958
     * @API： http://ydwiki.yidian-inc.com/pages/viewpage.action?pageId=71692093
     */
    @GetMapping("/GetDocDetail")
    public Response<DocContentVO> getDocDetail(
            @RequestParam("doc_id") @Pattern(regexp = "^[VT]_.*$", message = "doc_id参数不合法") String docId,
            @RequestParam("userid") @NotNull(message = "userid参数为空") Long userid,
            @RequestParam("platform") Long platform,
            @RequestParam("api_version") String apiVersion) {
        try {
            if (AppVersionUtil.getVersionFlag(platform, apiVersion)) {
                Boolean oldVersion = true;
                ThreadLocalContextHolder.put("oldVersion", oldVersion);
            }
            Response<DocContentVO> docDetail = null;
            return docDetail;
        }catch (Exception e){
            log.error("NewPlog exec exception : ",e);
            return Response.failed(e.getMessage(), null);
        }finally {
            ThreadLocalContextHolder.reset();
        }
    }

    @PostMapping("/GetDocsByDocids")
    public Response<List<Doc>> getDocsByDocids(@RequestBody @Validated DocRequestDTO docRequestDTO) {
        return null;
    }
}
